let initialstate = {
    token:'',
    name:'',
}
export default function WFLreducer(state = initialstate, action: any) {
    // 1.深拷贝state,得到一个全新的state
    let newState = JSON.parse(JSON.stringify(state))


    // 2.匹配动作类型,对state进行对应的处理
    if (action.type == 'SAVE_TOKEN') {
        newState.token = action.payload;
    }else if(action.type == 'REMOVE_TOKEN'){
        newState.token = '';
    }else if(action.type == 'SAVE_NAME'){
        newState.name = action.payload;
    }else{
        return state
    }
    

    // 3.返回处理后全新的state
    return newState
}